import { toRefs ,reactive,ref,computed } from "vue"

export const useCart = ()=>{
/** 响应式 API */
const {
  firstName,
  firstPrice,
  firstQuantity
} = toRefs(reactive({ firstName: 'First Product', firstPrice: 10, firstQuantity: 1 }));



const secondName = ref('Second Product')
const secondPrice = ref(20)
const secondQuantity = ref(2)

const total = computed(
  () =>
    ((firstPrice.value * firstQuantity.value + secondPrice.value * secondQuantity.value) *
      (100 - coupon.value)) /
    100
)
/** 变量存在提升 */
const coupon = ref(10)

const setCoupon = (percent) => (coupon.value = percent)

return {
  firstName,
  firstPrice,
  firstQuantity,
  secondName,
  secondPrice,
  secondQuantity,
  coupon,
  setCoupon,
  total
}
}
